package com.xkdx.guangguang.pushserviceforSelf;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;

public class PushServiceForSelfModule extends AbsModule {
	public ArrayList<PushForSelfInfo> pushInfoList;
	private JSONObject jsonObj;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			jsonObj = (JSONObject) backJson.get(0);
			pushInfoList = parsePushInfo(jsonObj);

		} catch (Exception e) {
			throw e;
		}

	}

	private ArrayList<PushForSelfInfo> parsePushInfo(JSONObject obj)
			throws Exception {
		ArrayList<PushForSelfInfo> list = new ArrayList<PushForSelfInfo>();
		try {
			if (obj == null) {
				return null;
			}
			JSONObject stut = (JSONObject) obj.get("DetailInfo");

			if (stut.getString("StatusCode").equals("1")) {
				JSONArray array = stut.getJSONArray("DetailInfo");
				if (!array.equals("") && array.length() > 0) {
					for (int i = 0; i < array.length(); i++) {
						PushForSelfInfo pushInfo = new PushForSelfInfo();
						JSONObject data = (JSONObject) array.opt(i);
						pushInfo.setID(data.getString("ID"));
						pushInfo.setMessage(data.getString("Msg"));
						pushInfo.setObjectType(data.getString("ObjectType"));
						pushInfo.setObjectValue(data.getString("ObjectID"));
						pushInfo.setSelfNotificationState(true);
						list.add(pushInfo);
					}
					return list;
				}
			} else {
				return null;
			}

		} catch (Exception e) {
			e.printStackTrace();
			throw e;
		}
		return list;
	}

}
